<?php

namespace App\Service\UserCenter\v1_1_8;

use App\Model\Service\CacheService;
use App\Model\Setting\SettingUserLevel;
use App\Model\UserProfile;
use App\Service\BaseService;


use App\Constants\ErrorCode;

/**
 * 收费设置列表
 */
class CoinSettingService extends BaseService
{
    public function handle()
    {
        //收费类型：0-默认语音，1-视频，2-私聊收费
        $coinType = $this->request->input('coin_type', 0);
        //设置
        switch ($coinType) {
                //语音
            case 0:
                $text = "接听语音";
                $coinField = 'coin_setting';
                break;
                //视频
            case 1:
                $text = "接听视频";
                $coinField = 'video_coin_setting';
                break;
                //文字
            case 2:
                $text = "接收私信";
                $coinField = 'chat_coin_setting';
                break;
        }
        $coinField == 'coin_setting' && $coinField = 'voice_coin_setting';
        $settings = CacheService::getCoinSetting($coinField);
        $userId = $this->getUserId();
        $profile = UserProfile::getProfile($userId);
        $myLevel = SettingUserLevel::getUserLevel($profile);
        array_walk($settings, function (&$setting) use ($profile, $coinField, $myLevel) {
            $setting['text'] = $setting['coin'] == 0 ? "免费" : "{$setting['coin']}金币/分钟";
            $myLevel < $setting['level_limit'] && $setting['text'] .= "（魅力lv{$setting['level_limit']}以上）";
            $setting['selected'] = $profile && $profile->{$coinField} == $setting['coin'] ? 1 : 0;
            $setting['level_limit'] = $setting['charm_limit'];
        });
        $ret['my_level'] = $myLevel;
        $ret['list'] = $settings;
        $ret['setting_text'] = '收费设置说明:
1、开启“接听语音”、“接听视频”并完成资费设置，接听音视频通话即可获得收益;
2、您可根据自身特色设置资费，用户魅力等级越高可设置的资费越高;不同话单资费说明:

话单类型说明：
1、常规话单: 对方通过你的个人主页精准向你发起通话，按照你设置的资费进行计费。
2、天天福利: 系统提供每日一次免费通话，按照语音通话10金币/分钟、视频通话20金币/分钟进行计费。
3、随心聊: 系统提供根据在线状态匹配，按照语音通话15金币/分钟、视频通话30金币/分钟进行计费。';
        $ret['setting_link'] = 'http://web.xtiaowa.com/coinsetting.html';

//	return $this->setError(ErrorCode::USER_NOT_VALID, $ret);

	return $ret;
    }
}
